package com.quectel.sdk.dahua9100;

import com.quectel.sdk.ex.hikisc.HikFactoryErrorException;

/**
 * 海康实例建造器
 *
 * @author: rananxin
 * @email: ryan.ran@quectel.com
 * @date: 2022-10-19 11:01:00
 */
public class Dahua9100ClientBuilder {

    /**
     * appKey访问凭证
     */
    private String username;
    /**
     * secretKey访问凭证
     */
    private String password;

    /**
     * 海康isc地址
     */
    private String ip;

    private Dahua9100ClientBuilder() {
    }

    public static Dahua9100ClientBuilder builder() {
        return new Dahua9100ClientBuilder();
    }

    public Dahua9100ClientBuilder username(String username) {
        this.username = username;
        return this;
    }

    public Dahua9100ClientBuilder password(String password) {
        this.password = password;
        return this;
    }


    public Dahua9100ClientBuilder ip(String ip) {
        this.ip = ip;
        return this;
    }

    public <T extends AbstractDahua9100BaseClient> T build(Class<T> executorCls) {
        if (ip == null || username == null || password == null) {
            throw new HikFactoryErrorException("Missing request parameter.");
        }
        try {
            T t = executorCls.newInstance();
            t.setRequester(Dahua9100Requester.getInstance(username, password, ip));
            return t;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
